﻿using Anley.DomainDrivenDesign.Contract.Enums;

namespace Anley.DomainDrivenDesign.Contract.Application;

/// <summary>
/// 全局异常处理类
/// </summary>
public class GlobalExceptionFilter
    : IExceptionFilter
{
    /// <summary>
    /// 异常
    /// </summary>
    /// <param name="context"></param>
    public void OnException(ExceptionContext context)
    {
        var message = context.Exception.Message ?? "服务器错误";
        var result = AneResult.Error(AneResultCode.InternalServerError, message);
        context.Result = new JsonResult(result);
        context.ExceptionHandled = true;
    }
}